﻿@model IEnumerable<FILSTARTUPS_CMS.Models.CategoryPage>
@{
    ViewBag.Title = "Index";
}
@section Pagename
{
    <h2>
        Category <small>Sub Pages</small></h2>
}
@if (TempData["message"] != null)
{
    <div class="alert-message success span12" id="tempdata">
        <center>@TempData["message"]</center>
    </div>
}
<!-- START ROW -->
<div class="row">
    <div class="span4">
        <h2>
            Create Category</h2>
        <div class="createclass">@Html.ActionLink("Create Category", "Create", "Category")</div>
    </div>
    <!-- END SPAN4 -->
    <!-- SPAN10 -->
    <script src="@Url.Content("~/Scripts/jquery.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui.min.js")" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            //        "{ 'query': '" + request.term + "' }",
            $('#query').autocomplete({
                source: function (request, response) {
                    var parameters = ["query", request.term, "pageidFK", $('#pageidFK').val()];
                    var paramList = '';
                    if (parameters.length > 0) {
                        for (var i = 0; i < parameters.length; i += 2) {
                            if (paramList.length > 0) paramList += ',';
                            paramList += '"' + parameters[i] + '":"' + parameters[i + 1] + '"';
                        }
                    }
                    paramList = '{' + paramList + '}';
                    $.ajax({
                        url: '/Category/GetCategory',
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        datatype: "json",
                        data: paramList,
                        success: function (data) {
                            response($.map(data, function (item) {
                                return { label: item.categoryname, value: item.categoryname };
                            }))
                        }
                    });
                },
                minLenght: 2
            });
        });   

    </script>
    <div class="span10">
        @using (Ajax.BeginForm("SearchPage", "Category", new AjaxOptions
    {
        HttpMethod = "GET",
        UpdateTargetId = "categorylist",
        InsertionMode = InsertionMode.Replace
    }, new { @class = "form-stacked" }))
        {
            <fieldset>
                <legend>Filtering & Searching</legend>
                @Html.DropDownList("pageidFK", new SelectList(ViewData["Pages"] as System.Collections.IEnumerable,
                                         "pageidPK", "Pagetitle"), "------All------")
                <input type="text" id="query" name="query" />
                <input type="submit" value="Filter" style="margin: 5px;" />
            </fieldset>
        }
        <div id="categorylist">
            @Html.Partial("_CategoryList")
        </div>
    </div>
    <!--END SPAN10-->
</div>
<!-- END ROW -->
